package day6;

import java.io.File;
import java.util.LinkedList;

/**
 * @author oldliu
 * @since 1.0
 */
public class FileSize {
    public static void reverse(File f) {
        LinkedList<File> files = new LinkedList<>();
        files.add(f);
        long cd = 0;
        while (files.size() > 0) {
            File temp = files.removeFirst();
            File[] fr = temp.listFiles();
            if (fr == null) {//不是文件夹
                cd += temp.length();
                continue;
            }
            for (File t : fr) {
                files.add(t);
            }
        }
        System.out.println("目录占用:" + cd);
    }


    public static void main(String[] args) {
        File f = new File("D:\\Documents\\桌面");
        reverse(f);
        //System.out.println(f.length());
    }
}
